
GameHandler = {};
local this = GameHandler;

function GameHandler.New(handlers)
    handlers[Protocal.ReqReady] = this.OnReady;
    handlers[Protocal.RspSendPais] = this.OnSendPais;

    handlers[Protocal.RspRobTurn] = this.OnRobTurn; 
    handlers[Protocal.RspLandlord] = this.OnLandlord;
    handlers[Protocal.ReqNotRob] = this.OnNotRob;

    handlers[Protocal.RspPutTurn] =this.OnPutTurn;
    handlers[Protocal.ReqPutCard] = this.OnPutCard;
    handlers[Protocal.ReqPassCard] = this.OnPassCard;
    
    handlers[Protocal.RspGameOver] = this.OnGameOver;
    handlers[Protocal.ReqRestart] = this.OnRestart;
    handlers[Protocal.ReqQuit] = this.OnQuit;
end

--玩家准备
function GameHandler.OnReady(message)
    local data=protobuf.decode("lin.RspReady",message);
    GamePanel.PlayerReady(data.seatId);
end

--开始发牌
function GameHandler.OnSendPais(message)
    local data=protobuf.decode("lin.RspSendPai",message);
    GamePanel.ReceivePai(data.pais);
end

--叫地主回合
function GameHandler.OnRobTurn(message)

    local data = protobuf.decode("lin.RspSeatId",message);
    GamePanel.TurnToRob(data.seatId);
end

--广播不叫地主
function GameHandler.OnNotRob(message)
    local data = protobuf.decode("lin.RspSeatId",message);
    GamePanel.ShowNotRob(data.seatId,data.pais);
end

--广播叫地主
function GameHandler.OnLandlord(message)

    local data = protobuf.decode("lin.ReqPais",message);
    GamePanel.RobLandLord(data.seatId,data.pais);
end 

--出牌回合
function GameHandler.OnPutTurn( message )
    local data = protobuf.decode("lin.RspSeatId",message);
    GamePanel.TurnToPut(data.seatId)
end

--玩家出牌
function GameHandler.OnPutCard(message)
    local data = protobuf.decode("lin.ReqPais",message);
    GamePanel.PutCard(data);
end

--广播要不起
function GameHandler.OnPassCard( message )
    local data = protobuf.decode("lin.RspSeatId",message);
    GamePanel.PutCard(data.seatId);
end

--y游戏结束
function GameHandler.OnGameOver( message )
    local data = protobuf.decode("lin.RspGameOver",message); 
    OverPanel.New(data);
    GamePanel.GameOver(data);
end

--重新开始
function GameHandler.OnRestart( message )
    local  data = protobuf.decode("lin.RspSeatId",message);
    GamePanel.Restart(data.seatId);
end

--退出游戏
function GameHandler.OnQuit( message )
    local  data = protobuf.decode("lin.RspGameOver",message);
end